package main

import "fmt"

func main() {
	for1()
	for2()
	for3()
	for4()
	for5()
}
func for1() {
	sum := 0
	for i := 0; i <= 10; i++ {
		sum += i
	}
	fmt.Println(sum)
}

/**
类似while
*/
func for2() {

	sum := 1
	for sum <= 10 {
		sum += sum
	}

	fmt.Println(sum)
	sum = 1

	for sum <= 10 {
		sum += sum
	}
	fmt.Println(sum)
}

/**
无限循环
*/
func for3() {
	sum := 0
	for {
		sum++
		if sum > 10 {
			break
		}
	}
	fmt.Println(sum)
}

/**
带下标的循环
*/
func for4() {
	strings := []string{"google", "runoob"}
	for i, s := range strings {
		fmt.Println(i, s)
	}
}

/**
goto 语句,跳过打印15
*/
func for5() {
	a := 10
LOOP:
	for a < 20 {
		if a == 15 {
			a = a + 1
			goto LOOP
		}
		fmt.Println("a的值为：%d", a)
		a++
	}
}
